import React from 'react'
import router from 'next/router'
import axios from 'axios'
import { hostname } from '../config/host.config'

export function Auto(childrenComponent) {
    return class AutoWrapper extends React.Component {
        constructor(props) {
            this.setState({
                router: null,
                flag: 0 // 1的代表认证通过，2代表认证失败,0代表超时
            })
        }
        componentDidMount() {
            axios.get(hostname + '/login/userInfo').then((data) => {
                
            })
        } 
        render() {
            // 1的代表认证通过，2代表认证失败,0代表超时
            if (this.state.flag == 1) {
                return <childrenComponent {...props} />
            } else if (this.state.flag == 2) {
                // 记录当前路由，登录后做路由设置
            } else {
                router.push("/")
            }
        }
    }
}